package com.aishua.fire.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.aishua.fire.entity.permpermteam.PermpermteamInfo;
import com.aishua.fire.jpa.PermPermteamDao;
import com.aishua.fire.jpa.entity.PermPermteam;
import com.aishua.fire.jpa.entity.PermPermteamId;
import com.aishua.fire.mapper.PermpermteamMapper;
import com.aishua.fire.mapper.dto.PermPermteamDto;
import com.aishua.fire.service.PermPermteamService;

@Service
public class PermPermteamServiceImpl implements PermPermteamService{
	
	
	@Autowired
	private PermPermteamDao permPermteamDao;
	
	@Autowired
	private PermpermteamMapper permpermteamMapper;
	
	/**
	 * 删除权限中间表信息
	 */
	@Override
	public void deletePermPermteam(PermPermteamDto permPermteamDto) {
		
		permpermteamMapper.deletePermPermteam(permPermteamDto);
	}
	
	
	
	
	/**
	 * 权限中间表更新子权限
	 */
	@Override
	public void updatePermPermteam(PermPermteamDto permPermteamDto){
	 	
		permpermteamMapper.deletePermPermteam(permPermteamDto);
		permpermteamMapper.updatePermPermteam(permPermteamDto);
	
	}
	
	/**
	 * 重复校验
	 * @param permPermteamDto
	 * @return
	 */
	public String  findCountPermPermteam(PermPermteamDto permPermteamDto) {
		
		int countPP= permpermteamMapper.findCountPermPermteam(permPermteamDto);
		if(countPP==0) {
		   return "norepeat";	
		}else {
		     return "repeat";
		} 
	}

	@Override
	public void addPermPermteam(PermpermteamInfo permpermteamInfo) {
		List<Long> permIds = permpermteamInfo.getPermIds();
		
		   for(Long permId:permIds) {
			   PermPermteam permPermteam = permPermteamDao.findByUnionId(permpermteamInfo.getPermteamId(), permId);
			   if(permPermteam == null) {
				   permPermteam = new PermPermteam();
				   permPermteam.setPermpermteamId(new PermPermteamId(permpermteamInfo.getPermteamId(), permId));
				   permPermteamDao.save(permPermteam);
			   }
		   }
	}
	
	
}

